package com.yunxi.service.dubboService.impl.finance;

import com.github.pagehelper.PageInfo;
import com.yunxi.finance.pojo.RebateCommissionQueryReqVO;
import com.yunxi.finance.pojo.RebateCommissionQueryRespVO;
import com.yunxi.finance.pojo.RebateCommissionUpdateReqVO;
import com.yunxi.finance.service.RebateCommissionDubboService;
import com.yunxi.model.finance.RebateCommission;
import com.yunxi.service.localService.finance.RebateCommissionService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * <p>
 * 固定返利表 服务实现类
 * </p>
 *
 * @author 
 * @since 2019-09-16
 */
public class RebateCommissionDubboServiceImpl implements RebateCommissionDubboService {

    @Autowired
    @Qualifier(value = "rebateCommissionServiceImpl")
    RebateCommissionService rebateCommissionService;


    @Override
    public RebateCommissionQueryRespVO getById(String id) throws InvocationTargetException, IllegalAccessException {
        RebateCommission rebateCommission = rebateCommissionService.getById(id);
        RebateCommissionQueryRespVO rebateCommissionVO = new RebateCommissionQueryRespVO();
        BeanUtils.copyProperties(rebateCommission,rebateCommissionVO);
        return rebateCommissionVO;
    }

    @Override
    public void saveOrUpdate(RebateCommissionQueryReqVO rebateCommissionVO) throws InvocationTargetException, IllegalAccessException {
        RebateCommission rebateCommission = new RebateCommission();
        BeanUtils.copyProperties(rebateCommissionVO,rebateCommission);
        rebateCommissionService.saveOrUpdate(rebateCommission);
    }

    @Override
    public void removeById(String id) {
    rebateCommissionService.removeById(id);
    }

    @Override
    public PageInfo<RebateCommissionQueryRespVO> findPageByVO(RebateCommissionQueryReqVO rebateCommissionVO, Integer pageNum, Integer pageSize) throws InvocationTargetException, IllegalAccessException {
      PageInfo<RebateCommissionQueryRespVO> pageInfo = rebateCommissionService.pageByVo(rebateCommissionVO,pageNum,pageSize);
      return pageInfo;
   }

    @Override
    public void removeByListVo(List<RebateCommissionQueryReqVO> rebateCommissionVOList) throws IllegalAccessException, InvocationTargetException, InstantiationException {
        rebateCommissionService.removeByListVo(rebateCommissionVOList);
    }

    @Override
    public List listByVo(RebateCommissionQueryReqVO rebateCommissionVO) {
      return rebateCommissionService.listByVo(rebateCommissionVO);
    }

    @Override
    public void updateBatch(RebateCommissionUpdateReqVO vo) {
       if(vo == null || vo.getList() == null){
           throw new RuntimeException("RebateCommissionUpdateReqVO vo对象不能为空!");
       }

        for(RebateCommissionQueryReqVO entity : vo.getList()){
             RebateCommission rebateCommission = new RebateCommission();
             BeanUtils.copyProperties(entity,rebateCommission);
             rebateCommissionService.updateById(rebateCommission);
        }
    }
}
